import java.util.ArrayList;
import java.util.List;

import org.testng.AssertJUnit;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class TestRockPaperScissors {
	
	private RockPaperScissors rps;
	private List<RPSEnum> p1;
	private List<RPSEnum> p2;
	
	public void testRockPaperScissors(){
		
	}
	
	@BeforeClass
	public void setUpClass(){
		rps = new RockPaperScissors();
		
		p1 = new ArrayList<RPSEnum>();
		p1.add(RPSEnum.PAPER);
		p1.add(RPSEnum.ROCK);
		
		p2 = new ArrayList<RPSEnum>();
		p2.add(RPSEnum.SCISSORS);
		p2.add(RPSEnum.PAPER);
	}
	
	@AfterClass
	public void tearDownClass(){
		rps = null;
		p1 = null;
		p2 = null;
	}

	

	@Test(dataProvider = "P1lose", dependsOnGroups = { "predefined games" })
	public void testPlayerRandom(Player p1, Player p2)
	{
		
	}
	
	

	
	@DataProvider(name = "random")
	public Object[][] createRandomPlayersData() {
	 return new Object[][] {
	   { new Player("p1", Player.aleaFill(10)), new Player("p2", Player.aleaFill(10)) }
	 };
	}
	
	
	/*
	 * Test play(Player p1, player p2) methods
	 */
	
	@Test(dataProvider = "P1lose", dependsOnGroups = { "one move" }, groups = "predefined games")
	public void testPlayerLose(Player p1, Player p2)
	{
		AssertJUnit.assertEquals(rps.play(p1, p2), Result.LOST);
	}
	
	@Test(dataProvider = "P1win", dependsOnGroups = { "one move" }, groups = "predefined games")
	public void testPlayerWin(Player p1, Player p2)
	{
		AssertJUnit.assertEquals(rps.play(p1, p2), Result.WIN);
	}
	
	@Test(dataProvider = "TiePlay", dependsOnGroups = { "one move" }, groups = "predefined games")
	public void testPlayerTie(Player p1, Player p2)
	{
		AssertJUnit.assertEquals(rps.play(p1, p2), Result.TIE);
	}
	

	@DataProvider(name = "P1lose")
	public Object[][] createLosingP1Data() {
	 return new Object[][] {
	   { new Player("p1", p1), new Player("p2", p2) }
	 };
	}
	
	@DataProvider(name = "P1win")
	public Object[][] createWinningP1Data() {
	 return new Object[][] {
	   { new Player("p1", p2), new Player("p2", p1) }
	 };
	}
	
	@DataProvider(name = "TiePlay")
	public Object[][] createTieData() {
	 return new Object[][] {
	   { new Player("p1", p1), new Player("p2", p1) }
	 };
	}
	
	
	/*
	 * Test play(RPSEnum p1, RPSEnum p2) methods
	 */
	
	@Test(dataProvider = "winned", groups = { "one move" })
	public void testWinPlay(String p1, String p2)
	{
		AssertJUnit.assertEquals(rps.play(RPSEnum.valueOf(p1), RPSEnum.valueOf(p2)), Result.WIN);
	}
	
	@Test(dataProvider = "tied", groups = { "one move" })
	public void testTiePlay(String p1, String p2)
	{
		AssertJUnit.assertEquals(rps.play(RPSEnum.valueOf(p1), RPSEnum.valueOf(p2)), Result.TIE);
	} 
	
	@Test(dataProvider = "failed", groups = { "one move" })
	public void testLostPlay(String p1, String p2)
	{
		AssertJUnit.assertEquals(rps.play(RPSEnum.valueOf(p1), RPSEnum.valueOf(p2)), Result.LOST);
	}
	

	@DataProvider(name = "winned")
	public Object[][] createWinningData() {
	 return new Object[][] {
	   { "PAPER", "ROCK" },
	   { "SCISSORS", "PAPER" },
	   { "ROCK", "SCISSORS" }
	 };
	}
	
	@DataProvider(name = "tied")
	public Object[][] createTyingData() {
	 return new Object[][] {
	   { "ROCK", "ROCK" },
	   { "PAPER", "PAPER" },
	   { "SCISSORS", "SCISSORS" }
	 };
	}
	
	@DataProvider(name = "failed")
	public Object[][] createFailingData() {
	 return new Object[][] {
	   { "ROCK", "PAPER" },
	   { "PAPER", "SCISSORS" },
	   { "SCISSORS", "ROCK" }
	 };
	}
}
